/**
 * @file     numIdenticalPairs.js
 * @brief    [1512. 好数对的数目](https://leetcode.cn/problems/number-of-good-pairs/)
 * @author   Zhu
 * @date     2024-12-03 11:20
 */

/**
 * @param {number[]} nums
 * @return {number}
 */
var numIdenticalPairs = function (nums) {
    const dict = {};
    for (let i = 0; i < nums.length; i++) {
        if (dict[nums[i]] == undefined) {
            dict[nums[i]] = 1;
        } else {
            dict[nums[i]]++;
        }
    }

    const count = (size) => ((size - 1 + 1) * (size - 1)) / 2;
    let res = 0;
    for (const p in dict) {
        res += count(dict[p]);
    }

    return res;
};
